<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <title>留言发布</title>
    <style>
      /** {*/
      /*  vertical-align: bottom;*/
      /*}*/
      textarea {
        resize: none;
        outline: none;
        border: 1px solid pink;
        width: 300px;
        height: 200px;
        font-size: 16px;
        vertical-align: bottom;
      }
      button {
        margin-left: 10px;
        background-color: pink;
        border: 1px solid hotpink;
      }
      li {
        width: 300px;
        font-size: 16px;
        color: pink;
      }
      .delete {
        float: right;
        text-decoration: none;
        color: black;
      }
    </style>
  </head>
  <body>
    <textarea></textarea><button>提交</button>
    <ul></ul>
    <script>
      var button = document.querySelector("button");
      var text = button.previousElementSibling;
      var ul = button.nextElementSibling;

      button.onclick = function () {
        //console.log(1);
        console.log(text.value);
        if (text.value) {
          var li = document.createElement("li");
          li.innerHTML =
            text.value + "<a href='javascript:;' class='delete'>删除</a>";
          ul.appendChild(li);
          var delet = document.querySelectorAll(".delete");
          for (let i = 0; i < delet.length; i++) {
            console.log(delet[i]);
            delet[i].onclick = function () {
              ul.removeChild(this.parentNode);
            };
          }
        }
      };
    </script>
  </body>
</html>
